$('.input-daterange').datepicker({
  language: "zh-CN"
});
$(function () {
  function handleBaseUserBtnClick() {
    if(baseUserTime === 60){
      $('#base-user-btn').attr('disabled', true);
      $.get('/api/baseUserCaptcha?idcard=' + $('#base-user-id').val()).then(function() {
        baseUserInterval = setInterval(function(){
          if(baseUserTime === 0) {
            clearInterval(baseUserInterval);
            $('#base-user-btn').text('获取验证码').attr('disabled', false);
            baseUserTime = 60;
          } else {
            baseUserTime--;
            $('#base-user-btn').text(baseUserTime + 'S');
          }
        }, 1000);
      }).catch(function(){
        $('#base-user-btn').attr('disabled', false);
      });
    }
  }

  function freshCaptcha() {
    var phone = $('#phone').val();
    if(phone.length !== 11 || (phone[0] != 1)) {
      warning_prompt('手机号码格式不正确');
      return;
    }
    $.get('/api/newPatientCaptcha?phone=' + phone).then(function(res) {
      if(_.get(res, 'code') === 0) {
        $('.captcha-box>img').attr('src', _.get(res, 'data'));
      }
    });
  }

  var addPatients = new Vue({
    el:"#addPatients",
    data:{
      patientsName:"",
      patiensPhone:"",
      emergencyPhone:"",
      identityCard:"",
      patientsSex:"",
      nation:""
    },
    methods:{
      addPatients:function () {
        var that = this;
        var sex = 1;
        if (that.patientsSex=="女"){
          sex = 2;
        }
        axios.post("../api/patients/add",{
          patientsName:that.patientsName,
          patiensPhone:that.patiensPhone,
          emergencyPhone:that.emergencyPhone,
          identityCard:that.identityCard,
          patientsSex:sex,
          nation:that.nation
        },{headers:{'token':localStorage.getItem('token')}}).then(function(response){
          if (response.data.code!="0"){
            alert(response.data.msg)
          }
          alert("添加数据成功");
          location.href="user_list.html";
        }).catch(function(err){
          console.log(err);
        });
      }
    }
  })

  var getTokenVue = new Vue({
    el:"#getToken",
    data:{
      token:localStorage.getItem("token")
    }
    ,methods:{

    }
  })

});

